<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
JTable::addIncludePath ( JPATH_COMPONENT. DS . 'tables' );
//kiem tra dang nhap va phan quyen
    $user = JFactory::getUser();
  
    $db=&JFactory::getDBO();
    $id = $user->get('id');
    $_SESSION['id_user'] = $id;
                    $lenh = "SELECT count(*) FROM #__erp_employee_profile where id = '".$id."'";
                    $db->setQuery($lenh);
                    $rs = $db->loadResult();
                    
                    if($rs==1)
                    {   
                        $lenh = "SELECT count(*) FROM #__erp_employee_access where id_user = '".$id."' and id_function =6";
                        $db->setQuery($lenh);
                        $rs2 = $db->loadResult(); 
                        if($rs2 == 1)
                        {
                            $lenh = "SELECT count(*) FROM #__erp_agent_branch_user where id_user = '".$user->get('id')."'";
                            $db->setQuery($lenh);
                            $rs3 = $db->loadResult();
                            
                            if($rs3 > 0)
                            {
                                
                                global $mainframe;
                                $mainframe->redirect( "index.php", "B?n không có ch?c nang này.",'error');
                                return; 
                            }    
                            else
                            {
                                 $_SESSION['id_a_b'] = 0;
                                 $lenh = "SELECT * FROM #__erp_sale_config where id_brand = '".$_SESSION['id_a_b']."' ";
                                 $db->setQuery($lenh);
                                 $_SESSION['config'] = $db->loadObject();
                            }   
                        }
                        else
                        {
                                global $mainframe;
                                $mainframe->redirect( "index.php", "B?n không có ch?c nang này.",'error');
                                return; 
                        }
                    }
                    else
                    {
                        
                                global $mainframe;
                                $mainframe->redirect( "index.php", "B?n không có ch?c nang này.",'error');
                                return; 
                    }
                   
$controller = JRequest::getVar('view', 'su_luoc_che_bien' );//trang mac dinh
$path = JPATH_COMPONENT . DS . 'controllers' . DS . $controller . '.php';
$user = & JFactory::getUser();
if (file_exists ( $path )) {
	require_once $path;
} else {	
	require_once JPATH_COMPONENT . DS . 'controllers' . DS . 'controller.php';
}
$classname = 'sale_tsc_che_bienController' . ucfirst($controller);//doi ten com
$controller = new $classname (); 
$controller->execute ( JRequest::getVar ( 'task' ) );
$controller->redirect ();